﻿using Newtonsoft.Json;
using System;

namespace Shared.Service.Http
{
    public class AccessToken
    {
        public AccessToken(string token, long expireIn)
        {
            Token = token;
            ExpireIn = expireIn;
        }

        [JsonProperty("access_token")]
        public string Token { get; set; }

        private long _expireIn;

        [JsonProperty("expires_in")]
        public long ExpireIn
        {
            get => _expireIn;
            set
            {
                if (value > 0)
                {
                    _expireIn = value;
                    ExpiredTime = DateTime.UtcNow.AddSeconds(value);
                }
            }
        }

        [JsonIgnore]
        public DateTime ExpiredTime { get; private set; } = DateTime.UtcNow;

        public bool IsExpired()
        {
            return DateTime.UtcNow > ExpiredTime;
        }
    }
}
